Skip to content

fix(#3265781): add resource type route default for single-bundle views - #14

Closed
Decipher wants to merge 4 commits into
8.x-1.xfrom
feature/3265781-openapi-resource-type
Closed

fix(#3265781): add resource type route default for single-bundle views#14
Decipher wants to merge 4 commits into
8.x-1.xfrom
feature/3265781-openapi-resource-type

Conversation

@Decipher

@Decipher Decipher commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Fixes #3265781.

jsonapi_views-generated routes never carried the resource_type route default that route/resource introspection code (for example the OpenAPI module's JSON:API discovery) reads to resolve a route to a single ResourceType.

This does not use the community patch's/MR !18's approach. Both the original 2022 patch and the 2026 MR add new ResourceType('view', 'view', ViewsResource::class) - a fake type unrelated to the view's real entity type/bundle(s). I installed drupal/openapi_jsonapi and called its generator directly against a real site: that fake type produces zero-schema, generically-tagged ("View") OpenAPI entries for every exposed view, regardless of its real bundle(s). It avoids a crash but replaces it with silently wrong documentation. I also found the originally reported crash no longer reproduces against current openapi/openapi_jsonapi releases at all - their own null-guard (added 2020, in getPaths()) already excludes routes with no resource_type default rather than erroring.

Instead: a view can span multiple bundles (_jsonapi_resource_types, plural, already reflects this), so a single resource_type default only has one unambiguous answer when the view's entity type has exactly one bundle. For that case, this sets the real ResourceType already returned by resourceTypeRepository->get() - no fabrication needed. For a view spanning several bundles, the default is left unset rather than reporting a made-up type.

Verified manually against the real openapi/openapi_jsonapi modules (not just the Kernel test assertions): a single-bundle diagnostic view resolves a real schema ($ref: #/definitions/user--user); a multi-bundle diagnostic view is correctly excluded.

Adds Kernel test coverage for both the single-bundle and multi-bundle cases.

Verified on Drupal 10 and 11 locally via make test-kernel and make lint.

Summary by CodeRabbit

  • Bug Fixes

    • Improved generated Views JSON:API routes to provide accurate resource type information.
    • Single-bundle Views now receive a specific resource type; multi-bundle Views avoid ambiguous defaults.
    • Views now exclude bundles without a resource type.
  • Tests

    • Added coverage for single-bundle, multi-bundle, and missing-resource-type route behavior.
  • Documentation

    • Documented JSON:API resource type default behavior.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Decipher, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e8544e8-55ac-4ed3-88ab-74857579bd06

📥 Commits

Reviewing files that changed from the base of the PR and between 8b8a2b7 and 543bbb3.

📒 Files selected for processing (1)
  • tests/src/Kernel/JsonapiViewsResourceKernelTest.php
📝 Walkthrough

Walkthrough

Generated JSON:API view routes now resolve bundle resource types. Single-bundle views receive a singular resource_type default. Multi-bundle views retain plural resource types and omit the singular default. Kernel tests cover missing resource types.

Changes

View route resource type

Layer / File(s) Summary
Conditional route resource type defaults
src/Routing/Routes.php
Resolves bundle resource types before extracting names. Skips views without resolved types. Assigns the singular resource_type default only when exactly one bundle remains.
Route resource type validation
tests/src/Kernel/JsonapiViewsResourceKernelTest.php, tests/src/Kernel/NullingResourceTypeRepository.php
Verifies multi-bundle omission, single-bundle ResourceType defaults, and removal of bundles without resource types.
Route resource type guidance
AGENTS.md, CHANGELOG.md
Documents plural defaults and conditional singular defaults for view routes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ViewRouteBuilder
  participant ResourceTypeRepository
  participant RouteMetadata
  ViewRouteBuilder->>ResourceTypeRepository: Resolve bundle ResourceType objects
  ResourceTypeRepository-->>ViewRouteBuilder: Return resolved types or NULL
  ViewRouteBuilder->>RouteMetadata: Set plural types and conditional singular default
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a resource type route default for single-bundle Views.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/3265781-openapi-resource-type

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.32%. Comparing base (67fb5ca) to head (543bbb3).

Additional details and impacted files
@@             Coverage Diff             @@
##           8.x-1.x      #14      +/-   ##
===========================================
+ Coverage    94.16%   94.32%   +0.16%     
===========================================
  Files            3        3              
  Lines          137      141       +4     
===========================================
+ Hits           129      133       +4     
  Misses           8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Decipher
Decipher force-pushed the feature/3265781-openapi-resource-type branch from 18d585a to 7eb9fda Compare August 6, 2026 06:51
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Decipher Decipher changed the title fix(#3265781): add resource type route default for OpenAPI export fix(#3265781): add resource type route default for single-bundle views Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Routing/Routes.php`:
- Around line 80-85: Update the route-building logic around the
bundle_resource_types mapping to remove unresolved NULL ResourceType results
before constructing resource_types and route defaults. Skip the route when no
bundle resource types resolve, and ensure single-bundle resource_type handling
never assigns NULL; add a Kernel test covering a view whose bundle resource type
is missing.

In `@tests/src/Kernel/JsonapiViewsResourceKernelTest.php`:
- Line 315: Update the assertion for JsonApiRoutes::RESOURCE_TYPE_KEY in the
multi-bundle route test to use hasDefault() and assert the default is absent,
rather than relying on getDefault() returning NULL. Preserve the existing route
setup and other assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55d5c820-ad18-4c4c-8d89-fd0cce38ca93

📥 Commits

Reviewing files that changed from the base of the PR and between 3e50d79 and 7eb9fda.

📒 Files selected for processing (3)
  • AGENTS.md
  • src/Routing/Routes.php
  • tests/src/Kernel/JsonapiViewsResourceKernelTest.php

Comment thread src/Routing/Routes.php Outdated
Comment thread tests/src/Kernel/JsonapiViewsResourceKernelTest.php Outdated
@Decipher
Decipher force-pushed the feature/3265781-openapi-resource-type branch 3 times, most recently from 9bd7f78 to d01e7e6 Compare August 8, 2026 23:58
@Decipher
Decipher force-pushed the feature/3265781-openapi-resource-type branch from d01e7e6 to 8b8a2b7 Compare August 9, 2026 00:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/src/Kernel/JsonapiViewsResourceKernelTest.php (1)

292-294: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the cache assertion non-vacuous.

The loop passes when callsByBundle is empty. That case does not prove that route rebuilding used CountingResourceTypeRepository. Assert that the spy recorded calls before checking each count.

Proposed fix
+    $this->assertNotEmpty($counting_repository->callsByBundle);
     foreach ($counting_repository->callsByBundle as $key => $count) {
       $this->assertSame(1, $count, "$key resolved more than once across the two views.");
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/src/Kernel/JsonapiViewsResourceKernelTest.php` around lines 292 - 294,
Make the cache assertion in the test method containing the callsByBundle loop
non-vacuous by first asserting that CountingResourceTypeRepository recorded at
least one call, then retain the per-bundle assertSame(1, $count) checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/src/Kernel/JsonapiViewsResourceKernelTest.php`:
- Around line 292-294: Make the cache assertion in the test method containing
the callsByBundle loop non-vacuous by first asserting that
CountingResourceTypeRepository recorded at least one call, then retain the
per-bundle assertSame(1, $count) checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e9ab77e5-78ca-4aca-b543-636b297141ef

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb9fda and 8b8a2b7.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/Routing/Routes.php
  • tests/src/Kernel/JsonapiViewsResourceKernelTest.php
  • tests/src/Kernel/NullingResourceTypeRepository.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Routing/Routes.php

@Decipher

Decipher commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Superseded — merged upstream on Drupal.org as 4b17574 (squash of this branch's commits) and fast-forwarded here.

@Decipher Decipher closed this Aug 9, 2026
@Decipher
Decipher deleted the feature/3265781-openapi-resource-type branch August 9, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant